<template>
    <el-main>
        <el-main class="ep-body">
            <epl-top-bar showCompany  companyType="COMPANY_AAB000_EXACT" cpTagType="COMPANY_SIMPLE_GROUP">
            </epl-top-bar>
            <epl-userMessage idCount="2" dataType="company">
                <epl-insurance></epl-insurance>
            </epl-userMessage>
            <el-card class="ep-card">
                <el-form :model="form" ref="form" :rules="rules">
                    <ep-title>单位参保信息</ep-title>
                    <el-row :gutter="10">
                        <ep-input colspan="8" label="单位参保日期" name="aab050"  :property="form.aab050" p="D"
                                  :datas="{formData:form}"></ep-input>
                        <ep-input colspan="8" label="单位参保状态" name="aab051"  :property="form.aab051" p="D"
                                  :datas="{formData:form}"></ep-input>
                    </el-row>
                    <ep-title>单位银行信息</ep-title>
                    <el-row :gutter="10" v-show="show">
                        <ep-input colspan="8" label="发放银行" name="aaz065" :property="form.aaz065" p="D"
                                  :datas="{formData:form}"></ep-input>
                        <ep-input colspan="8" label="银行账号" name="aae010" :property="form.aae010" p="D"
                                  :datas="{formData:form}"></ep-input>
                        <ep-input colspan="8" label="银行开户名" name="aae009" :property="form.aae009" p="D"
                                  :datas="{formData:form}"></ep-input>
                    </el-row>
                    <el-row :gutter="10">
                        <ep-input colspan="8" label="开户行行号" name="bab040" :property="form.bab040" p="D"
                                  :datas="{formData:form}"></ep-input>
                        <ep-input colspan="8" label="开户银行名称" name="bac049" :property="form.bac049" p="D"
                                  :datas="{formData:form}"></ep-input>
                    </el-row>
                    <ep-title>变更信息</ep-title>
                    <el-row :gutter="10">
                        <ep-select colspan="8" label="是否精减单位" name="isreduce" codetype="ISREDUCE"  placeholder="请选择是否精减单位" :property="form.isreduce" p="R"
                                  :datas="{formData:form}"></ep-select>
                        <ep-input colspan="8" label="变更日期" name="aae035"  :property="form.aae035" p="D"
                                  :datas="{formData:form}"></ep-input>
                    </el-row>
                    <el-row :gutter="10">
                        <ep-textarea :rows="3" colspan="24" label="备注" name="aae013" :property="form.aae013"
                                     placeholder="请输入备注" p="E" :datas="{formData:form}"></ep-textarea>
                    </el-row>

                    <el-row type="flex" justify="center">
                        <ep-saveButton id="doSave" type="primary" top="20" bottom="20" ref="save" @formValidate="formValidate"
                                       :validate="['form']"
                                       :datas="{formData: form,panel:panel}"></ep-saveButton>
                    </el-row>
                </el-form>
            </el-card>
        </el-main>
    </el-main>
</template>
<script type="es6">
    export default {
        data() {
            return {
                form:{
                    aab050: {
                        value: '',
                        p: 'D'
                    },
                    aab051: {
                        value: '',
                        p: 'D'
                    },
                    aaz065: {
                        value: '',
                        p: 'D'
                    },
                    aae010: {
                        value: '',
                        p: 'D'
                    },
                    aae009: {
                        value: '',
                        p: 'D'
                    },
                    bab040: {
                        value: '',
                        p: 'D'
                    },
                    bac049: {
                        value: '',
                        p: 'D'
                    },
                    isreduce: {
                        key: '',
                        value: '',
                        p: 'R'
                    },
                    aae035: {
                        value: '',
                        p: 'D'
                    },
                    aae013: {
                        value: '',
                        p: 'E'
                    },

                },
                panel: {},

                rules:{
                    isreduce: [
                        {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                    ],

                },
                codeTypes:{
                    ISREDUCE:[],

                },
                codeTypeFilters:{

                },
                pager: {
                    page: 1,
                    size: 10
                },
                total: 0,
            }
        },
        computed: {
            functionId() {
                if (this.$store.getters.init.path !== this.$route.path) return;
                if (this.$store.getters.init.mdParam === null || this.$store.getters.init.mdParam === undefined) return;
                if (this.$store.getters.init.mdParam.functionid === undefined) return;
                return this.$store.getters.init.mdParam.functionid;
            },
            backFun() {
                return this.$store.getters.backFun;
            },
            init_formData() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.form;
            },
            doInitformData: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.formData;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            init_panel() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.panel;
            },
            doInitpanel: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.panel;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            show() {
                if (this.$store.getters.common === null) return [];
                return this.$store.getters.common.show;
            },

        },
        created() {
            let param = {
                path: this.$route.path,
                codeTypes:this.codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:this.form,
                panel:this.panel

            };
            if (this.$route.query.keepAlive === undefined) {
                this.$store.dispatch('SET_INIT', param);
            }
        },
        watch: {
            init_formData: {
                handler(value) {
                    if (value == undefined) return;
                    this.getformData(value);
                },
                deep: true
            },
            doInitformData: {
                handler(value) {
                    if (value == undefined) return;
                    this.getformData(value);
                },
                deep: true
            },
            init_panel: {
                handler(value) {
                    if (value == undefined) return;
                    this.getpanel(value);
                },
                deep: true
            },
            doInitpanel: {
                handler(value) {
                    if (value == undefined) return;
                    this.getpanel(value);
                },
                deep: true
            },
            show: {
                handler(value) {
                    if (value == undefined) return false;
                    return value;
                },
                deep: true
            },

            backFun: {
                handler(value) {
                    if (value === null) return;
                    this.customBackFun();
                    let backFun = [];
                    backFun = value.split(',');
                    if (backFun.indexOf('rDoInit') >= 0) {
                        let codeTypes = {
                            ISREDUCE:[],

                        };
                        let form = {
                            aab050: {
                                value: '',
                                p: 'D'
                            },
                            aab051: {
                                value: '',
                                p: 'D'
                            },
                            aaz065: {
                                value: '',
                                p: 'D'
                            },
                            aae010: {
                                value: '',
                                p: 'D'
                            },
                            aae009: {
                                value: '',
                                p: 'D'
                            },
                            bab040: {
                                value: '',
                                p: 'D'
                            },
                            bac049: {
                                value: '',
                                p: 'D'
                            },
                            isreduce: {
                                key: '',
                                value: '',
                                p: 'R'
                            },
                            aae035: {
                                value: '',
                                p: 'D'
                            },
                            aae013: {
                                value: '',
                                p: 'E'
                            },

                        };
                        let panel= {};

                        let param = {
                            path: this.$route.path,
                            codeTypes:codeTypes,
                            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                            form:form,
                            panel:panel

                        };
                        this.$store.dispatch('SET_INIT', param);
                    }
                }
            }
        },
        mounted() {
            if (this.$store.getters.cacheData === null) return;
            if (this.$store.getters.cacheData[this.$route.path] === undefined)  return;
            if (this.$store.getters.cacheData[this.$route.path].path !== this.$route.path) return;
            if (this.$store.getters.cacheData[this.$route.path].form !== undefined) {
                this.getformData(this.$store.getters.cacheData[this.$route.path].form);
            }
            if (this.$store.getters.cacheData[this.$route.path].panel !== undefined) {
                this.getpanel(this.$store.getters.cacheData[this.$route.path].panel);
            }

        },
        beforeRouteLeave(to, from, next) {
            let param = {
                path: this.$route.path,
                codeTypes: this.$store.getters.codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:this.form,
                panel:this.panel

            };
            if (from) {
                this.$store.dispatch('SET_CACHEDATA', param);
            }
            next();
        },
        methods: {
            getformData(value) {
                this.form = value;
            },
            getpanel(value) {
                this.panel = value;
            },


            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            },
            handleEdit(id) {
                this.dialogFormVisible = true;
            },
            formValidate(value){
                if(value && value.length>0){
                    let btn = true;
                    value.forEach((item,index)=>{
                        if(!btn) return
                        this.$refs[item].validate((valid) => {
                            if (valid) {
                                btn = true;
                            } else {
                                btn = false;
                            }
                        });
                    })
                    if(btn) this.$refs.save.btn();
                }
            },

            customBackFun(){//自定义方法体
            },
        },
    }

</script>
